var docId = getCurrentDocument().getId();
var domainid = getDomainid();

var xmdh = getItemValueAsString("xmdh");
var sql_0 = "select '" + domainid + "' as domainid" +
    " , item_ztxt_mc as item_ztxt, item_phxt_mc as item_phxt, item_xqtcbm_pgry as item_xqpg " +
    " , item_sjbm_pgry AS ITEM_sjpg, ITEM_kfgs_pgry AS item_kfpg, item_ywbm_pgry as item_ywpg " +
    " from tlk_setuo_carryout sc where ITEM_sqdh = '" + xmdh + "'";
var result_0 = findBySQL(sql_0);
var xqpg = result_0.getItemValueAsString("xqpg");
var sjpg = result_0.getItemValueAsString("sjpg");
var kfpg = result_0.getItemValueAsString("kfpg");
var ywpg = result_0.getItemValueAsString("ywpg");

//1. 获取需要查询的部门
var users = xqpg + ";" + sjpg + ";" + kfpg + ";" + ywpg;
users = users.replace(/\;/g, '\',\'');

var sql_getDepts = "select '" + domainid + "' AS domainid, group_concat(distinct ifnull(d.name, '')) as item_depts from bpm.t_department d right join bpm.t_user u on u.defaultdepartment = d.id where u.id in('" + users + "')";
var depts = findBySQL(sql_getDepts).getItemValueAsString("depts");
var deptColumns = "sss";
if (null != depts) {
    var deptArray = splitText(depts, ",");
    for (var n = 0; n < deptArray.length; n++) {
        var deptColumn = getDeptColumnNameByDeptName(deptArray[n]);
        if (isNotNull(deptColumn)) {
            deptColumns = deptColumns + "," + deptColumn
        }

    }
}
var array = splitText(deptColumns, ",");

//2. 获取关联的系统
var sql = "select '" + domainid + "' as domainid,  " +
    " group_concat( " +
    " distinct IFNULL((   " +
    " case when (item_zxt is null or item_zxt = '')   " +
    " then item_xt   " +
    " else concat(item_xt, '-', item_zxt)   " +
    " end   " +
    " ),'')   " +
    " ) as item_data   " +
    " from tlk_budget_back  where parent = '" + docId + "'";
var result = findBySQL(sql);
var data = result.getItemValueAsString("data");
data = data.replace(",", '\',\'');

if (null != array && array.length > 0) {
    var sql_1 = "SELECT '" + domainid + "' AS domainid, concat( " +
        "   GROUP_CONCAT( DISTINCT IFNULL(sm." + array[1] + ", '')  SEPARATOR ';')";
    for (var i = 2; i < array.length; i++) {
        sql_1 = sql_1 + " , ';', GROUP_CONCAT( DISTINCT IFNULL(sm." + array[i] + ", '')  SEPARATOR ';')";
    }
    sql_1 = sql_1 + " ) AS item_data FROM tlk_system_manager sm WHERE " +
        " ( CASE WHEN ( sm.item_system_son IS NULL OR sm.ITEM_SYSTEM_SON = '' ) " +
        " THEN sm.ITEM_SYSTEM ELSE CONCAT( sm.ITEM_SYSTEM, '-', sm.ITEM_SYSTEM_SON ) END ) IN ( '" + data + "' )";
}
var result_1 = findBySQL(sql_1);
if (null != result_1) {
    var data_1 = result_1.getItemValueAsString("data");
    var a = splitText(data_1, ";");
    var userlist = createObject("java.util.ArrayList");
    for (var i = 0; i < a.length; i++) {
        if (a != null) {
            var userVO = getUserById(a[i]);
            userlist.add(userVO);
        }
    }
}

/**
 * 根据系统名称获取系统对应的列名
 * @param {} deptName 
 */
function getDeptColumnNameByDeptName(deptName) {
    if (isNotNull(deptName)) {
        if ("技术开发部".equals(deptName)) {
            return "item_tech_leader";
        } else if ("工程运行部".equals(deptName)) {
            return "item_oper_leader";
        } else if ("信息统计部".equals(deptName)) {
            return "item_info_leader";
        } else if ("市场一部".equals(deptName)) {
            return "item_mark1_leader";
        } else if ("市场二部".equals(deptName)) {
            return "item_mark2_leader";
        } else if ("清算部".equals(deptName)) {
            return "item_qs_leader";
        } else if ("其他".equals(deptName)) {
            return "item_others_leader";
        } else {
            return "item_zh_lingdao";
        }
    }
}

userlist;